# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Brett Cornwall <ainola@archlinux.org>

pkgname=tldr
pkgver=3.2.0
pkgrel=1
pkgdesc="Command line client for tldr, a collection of simplified and community-driven man pages."
arch=('any')
url="https://github.com/tldr-pages/tldr-python-client"
license=('MIT')
depends=('python-shtab' 'python-colorama' 'python-termcolor')
makedepends=(
    'python-build'
    'python-installer'
    'python-setuptools'  # Set in pyproject.toml build
    'python-sphinx-argparse'
    'python-wheel'
)
checkdepends=('python-pytest')
source=("https://github.com/tldr-pages/tldr-python-client/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('1535979548b49cd8b0312f2cd11f69ba3f710e16a27c074dc5a8cb5617d7f343df30ba01a83388b460508ab519045140852767bfc8ff1189d612d71a3d35d76b')

build() {
  cd "tldr-python-client-$pkgver"
  make -C docs
  python -m build --wheel --no-isolation
}

# https://github.com/tldr-pages/tldr-python-client/issues/209
#check() {
#  cd tldr-python-client-$pkgver
#  python -m pytest
#}

package() {
  cd "tldr-python-client-$pkgver"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname/"

  # Generate here instead of a .install for package reproducibility
  install -dm755 "$pkgdir/usr/share/bash-completion/completions/"
  install -dm755 "$pkgdir/usr/share/zsh/site-functions/"
  python "$pkgdir"/usr/lib/python*/site-packages/tldr.py --print-completion bash \
    > "$pkgdir/usr/share/bash-completion/completions/tldr"
  python "$pkgdir"/usr/lib/python*/site-packages/tldr.py --print-completion zsh \
    > "$pkgdir/usr/share/zsh/site-functions/_tldr"
}
